<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
	<title>重置账户</title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<!-- 引入bootstrap -->
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/bootstrap.min.css">
	<!-- 引入JQuery  bootstrap.js-->
	<script src="<%=request.getContextPath()%>/js/jquery-3.2.1.min.js"></script>
	<script src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
</head>
<body>
	<!-- 顶栏 -->
	<jsp:include page="top.jsp"></jsp:include>
	<!-- 中间主体 -->
	<div class="container" id="content">
		<div class="row">
			<jsp:include page="menu.jsp"></jsp:include>
			<div class="col-md-10">
				<div class="panel panel-default">
				    <div class="panel-heading">
						<div class="row">
					    	<h1 style="text-align: center;">重置用户账户</h1>
						</div>
				    </div>
				    <div class="panel-body">
						<form class="form-horizontal" name="reset" role="form" action="<%=request.getContextPath()%>/Password/doUserPasswordRest" id="editfrom" method="post" onsubmit="return check()">
							<font color="red" class="col-sm-2 control-label">
								<span id="message">${msg}</span>
							</font>
							<div class="form-group">
								  <label for="username" class="col-sm-2 control-label">账号名</label>
								  <div class="col-sm-5">
									  <input type="text" class="form-control" name="username" id="username" placeholder="请输入用户名">
								  </div>
							</div>
							<font color="red" class="col-sm-2 control-label">
								<span id="b"></span>
							</font>
							  <div class="form-group">
							    <label for="password" class="col-sm-2 control-label">密码</label>
							    <div class="col-sm-5">
							      <input type="password" class="form-control" id="password" placeholder="请输入密码(默认为123456)" name="password">
							    </div>
							  </div>
							<font color="red" class="col-sm-2 control-label">
								<span id="c"></span>
							</font>
							  <div class="form-group">
							    <label for="password2" class="col-sm-2 control-label">确认密码</label>
							    <div class="col-sm-5">
							      <input type="password" class="form-control" name="password2" id="password2" placeholder="请再次输入密码(默认为123456)">
							    </div>
							  </div>
							<font color="red" class="col-sm-2 control-label">
								<span id="d"></span>
							</font>
							<div class="form-group">
								<label class="col-sm-2 control-label" >权限级别</label>
								<div class="col-sm-5">
									<input type="text" id="JiBie" style="display: none">
									<label class="checkbox-inline">
										<input type="radio" name="role" value="0">admin
									</label>
									<label class="checkbox-inline">
										<input type="radio" name="role" value="1">student
									</label>
								</div>
							</div>
							  <div class="form-group" style="text-align: center">
								<button class="btn btn-default" type="submit" disabled="disabled" id="tijiao">提交</button>
								<button class="btn btn-default" onclick="return chongzhi()">重置</button>
							  </div>
						</form>
				    </div>
				</div>
			</div>
		</div>
	</div>
	<div class="container" id="footer">
	<div class="row">
		<div class="col-md-12"></div>
	</div>
	</div>
</body>
<script>
    $("#nav li:nth-child(6)").addClass("active")

	$(function () {
		$("#username").blur(function () {
			var name=$("#username").val();
			$.ajax({
				url:"${pageContext.request.contextPath}/Password/selectStudentByName",
				type:"POST",
				data:{
					"username":name
				},
				dataType:"json",
				success:function (resp) {
					if(resp.type=="success"){
						$("#message").text("ok");
						$("#JiBie").val(resp.role);
						var val=document.getElementById("JiBie").value;
						$(":radio[name='role'][value='" + val + "']").prop("checked", "checked");
						$('#tijiao').removeAttr("disabled");
					}else{
						$("#message").text("NO!");
						$('#tijiao').attr("disabled",true);
					}
				},
				error:function () {
					alert("查询失败")
				}
			})

		})
	})

    function chongzhi() {
        $("#username").val("");
        $("#password").val("");
		$("#password2").val("");
    }
	function check() {
		if(reset.password.value!=""||reset.password.value!=null || reset.password2.value!=""||reset.password2.value!=null) {
			if(reset.password.value != reset.password2.value) {
				alert("两次密码不正确");
				return false;
			}
		}
	}
</script>
</html>